// JointPart.h: interface for the JointPart class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_JOINTPART_H__FB063A65_15E2_49A2_8163_0E0374E98B71__INCLUDED_)
#define AFX_JOINTPART_H__FB063A65_15E2_49A2_8163_0E0374E98B71__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>
#include "JointPort.h"
#include "JointPortOwner.h"
#include "PartFormat.h"
#include "PropertiesOfProduct.h"
#include "PropertyStack.h"
using namespace PropertySystem;

class Part;
namespace JointSystem
{
class PartChain;

class AFX_EXT_CLASS JointPart : public JointPortOwner
{
	friend class JointPort;

public:
	JointPart( PartChain* owner = 0 );
	virtual ~JointPart();
	JointPart( const JointPart& aPart );

public:
	virtual BOOL CanAttachTo( Attachable* totherAtt );
	virtual AttachStatus AttachTo( Attachable* totherAtt );
	virtual BOOL PrepareData();
	virtual void Accept( AttachableVisitor& );

public:
	AttachStatus AttachToPart( JointPart* totherPart );
	AttachStatus AttachToJointPort( JointPort* aJPort );
	BOOL InitJointPorts();
	CString GenerateQueryString();

private:
	BOOL CanAttach();

public:
	JointPort* NewJointPort( JointPortFormer& aJPFormer );
	BOOL CreateQueryFieldsStringForJointPortFormer( JointPortFormer& aJPFormer, CString& strFields );

public:
	const CString& CatalogID() const { return m_ProductCatalogID; }
	const CString& PartFormatID() const { return m_strPartFormatID; }
	const CString& SpecKey() const { return m_strSpecKey; }
	void PartFormatID( const CString& partFormatID );
	void SpecKey( const CString& strSpecKey ) { m_strSpecKey = strSpecKey; }
	void CatalogID( const CString& catalogID ) { m_ProductCatalogID = catalogID; }
	PartFormat* Format();

private:
	CString m_ProductCatalogID;
	CString m_strPartFormatID;
	CString m_strSpecKey;
	PartFormat* m_Format;

public:
	void SetPropertyValue( const CString& propname, const _variant_t& val ) {
//		if ( Properties() ) Properties()->SetAt( propname, val );/*
		assert( GetProperties() );
		Variable* pVariable = GetProperties()->GetProperty( propname );
		if( pVariable != NULL )
			*pVariable = val;//*/
	}

private:
	void InitUnknownFields();
	PropertiesOfProduct* Properties() { return m_Props ? m_Props :
		m_Props = new PropertiesOfProduct( Format() ); }

public:
	void SetProperties(PropertySystem::PropertyStack* ps){
		m_Properties = ps;
	}
	PropertyStack* GetProperties() { return m_Properties; }

private:
	PropertiesOfProduct* m_Props;
	PropertyStack* m_Properties;
};
};

#endif // !defined(AFX_JOINTPART_H__FB063A65_15E2_49A2_8163_0E0374E98B71__INCLUDED_)
